package y24.m3;

import java.util.ArrayList;
import java.util.List;

public class Test10 {
    static class Solution {
        public static List<List<Integer>> threeSum(int[] nums) {
            List<List<Integer>> list = new ArrayList<>();
            for (int i = 0; i < nums.length - 2; i++) {
                for (int j = i + 1; j < nums.length - 1; j++) {
                    for (int k = i + 2; k < nums.length; k++) {
                        if (nums[i] + nums[j] + nums[k] == 0) {
                            List<Integer> num = new ArrayList<>();
                            int num1 = nums[i];
                            int num2 = nums[j];
                            int num3 = nums[k];
                            int count = 0;
                            for(int x = 0;x < list.size() || list.size() == 0;x++){
                                if (list.size()>0) {
                                    for (int y = 0; y < 3; y++) {
                                        int n = list.get(x).get(y);
                                        if (n == num1 || n == num2 || n == num3) {
                                            count++;
                                        }
                                    }
                                }
                            }
                            if(count <= 2 || list.size() == 0){
                                num.add(num1);
                                num.add(num2);
                                num.add(num3);
                                list.add(num);
                            }
                        }

                    }
                }
            }
            return list;
        }
    }

    public static void main(String[] args) {
        int[] num = {-1,0,1,2,-1,-4};
        System.out.println(Solution.threeSum(num));
    }
}
